﻿#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QtQml/QtQml>
//#include <QtQuick/QQuickItem>
#include <QtQuick>
#include "QCommonEx.h"
#include <QtWidgets>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
   //QGuiApplication app(argc, argv);
    //QApplication a(argc, argv);

    QtQuick2ApplicationViewer viewer;

    viewer.rootContext()->setContextProperty("backgroundColor", QColor(Qt::yellow));
    viewer.setMainQmlFile(QStringLiteral("qml/qml_test/main.qml"));
    viewer.showExpanded();

    //viewer.rootContext()->setContextProperty();
    QQuickItem* root = viewer.rootObject();
    //qDebug() << root->Left << root->Right << root->width() << root->height() << root->opacity()<< root->objectName();

    //qDebug() << root->objectName();
    QQuickItem* accountEdit = root->findChild<QQuickItem*>("accountEdit");
    if (accountEdit)
    {
        accountEdit->setProperty("placeholderText", QVariant("aaaaaa"));

        QVariant arg1 = "abc";
        QVariant returnVar = "abc1";
        QMetaObject::invokeMethod(accountEdit, "callbyc",
                                  Q_RETURN_ARG(QVariant, returnVar),Q_ARG(QVariant, arg1));
        //qDebug() << returnVar;
        int j = 0;
    }




    QCommonEx common;
    common.qucikView = &viewer;
    //common.qucikView = qobject_cast<QQuickView*>(&viewer);
    QQuickItem* login = root->findChild<QQuickItem*>("login");
    if (login)
    {
        QObject::connect(login, SIGNAL(clicked()), &common, SLOT(onClicked()));
       // QObject::connect(login, SIGNAL(clicked()), &viewer, SLOT(onClicked()));
    }

    return app.exec();
}
